<template>
  <div class="login">
    <div class="login-wrap">
      <h4 class="login-title">欢迎登录</h4>
      <div class="login-con-wrap">
        <el-form ref="form" :model="form">
          <el-form-item
           prop="username"
           :rules="[
            { required: true, message: '用户名不能为空'},
           ]"
          >
            <el-input
             size="small" 
             placeholder="请输入用户名" 
             v-model="form.username"
            >
              <template slot="prepend">
                <i class="el-icon-s-custom"></i>
              </template>
            </el-input>
          </el-form-item>
          <el-form-item
           prop="password"
           :rules="[
            { required: true, message: '密码不能为空'},
           ]"
          >
            <el-input
             size="small" 
             placeholder="请输入密码" 
             v-model="form.password"
            >
              <template slot="prepend">
                <i class="el-icon-lock"></i>
              </template>
            </el-input>
          </el-form-item>
          <el-button style="width:100%;" type="primary" size="small" @click="login">登录</el-button>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  data() {
    return {
      form: {
        username: "admin",
        password: "abcde"
      }
    };
  },
  methods: {
      //登陆方法
      login() {
          this.$http('login', this.form, 'post')
          .then(res => {
              this.$message({
                  message: '登陆成功',
                  type: 'success'
              })
              this.$store.commit('setToken', res.data.token)
              setTimeout(()=>{
                  this.$router.push({
                      name: 'home'
                  })
              }, 1500)
          })
      }
  }
};
</script>

<style scoped lang="scss">
.login {
  position: absolute;
  top: 0;
  height: 100vh;
  left: 0;
  width: 100%;
  background: url("https://file.iviewui.com/admin-dist/img/login-bg.0899ffa6.jpg")
    center center no-repeat;
  background-size: cover;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  .login-wrap {
    width: 300px;
    background: #fff;
    border-radius: 10px;
    margin-right: 160px;
    .login-title {
      height: 50px;
      line-height: 50px;
      text-indent: 15px;
      font-weight: bold;
      font-size: 14px;
      border-bottom: 1px solid #ddd;
    }
    .login-con-wrap {
      padding: 25px 15px;
    }
  }
}
</style>
